library(plotly)
library(tidyverse)
library(kableExtra)
library(DT)

load('data/covid_today.RData')
load('data/geojson.RData')

Map of New Cases

fig <-
  today_counties %>%
  filter(new_cases > 0) %>%
  mutate(cty_name = paste(county, 'County -', state)) %>%
  plot_ly(data = .) %>%
  add_trace(
    type="choroplethmapbox",
    geojson=geo_counties,
    locations=~fips,
    z=~new_cases,
    colorscale="YlOrRd",
    reversescale=T,
    text=~cty_name,
    hoverinfo='z+text',
    marker=list(line=list(
      width=0),
      opacity=0.5
    )
  ) %>%
  layout(
    mapbox=list(
      style="carto-positron",
      zoom =2,
      center=list(lon= -95.71, lat=37.09))
  )
fig

Table of New Cases and Deaths

 today_counties %>%
  select(State = state, County = county, Date = date, 'New Cases' = new_cases,
         'New Deaths' = new_deaths) %>%
  arrange(desc(`New Cases`)) %>%
  datatable(options = list(pageLength = 20)) %>%
  formatStyle(
    'New Cases',
    background = styleColorBar(today_counties$new_cases, 'steelblue')
  ) %>%
  formatStyle(
    'New Deaths',
    background = styleColorBar(today_counties$new_deaths, 'steelblue')
  )